package com.llkj.qingnianguoxue.login;

import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.base.BaseActivity;
import com.llkj.qingnianguoxue.http.HttpMethod;

/**
 * 注册协议
 */
public class AgreementActivity extends BaseActivity {
    public static final String FROM_CLASS = "from_class";
    public static final String WEB_URL = "url";
    private int mFromClass;//1注册协议,2关于我们
    private WebView webView;
    private String webUrl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_agreement_fitsystem);

        initStatusbar(TSATUSBAR_TYPE_BLACK_TEXT,rlTitle,R.color.gray_bar);

        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        if(bundle!=null){
            mFromClass = bundle.getInt("from_class");
        }

        String title = "协议";
        switch (mFromClass){
            case 1:
                title = "注册协议";
                webUrl = HttpMethod.LOGIN_REGISTERATION_PROTOCOL;
                break;
            case 2:
                title = "关于我们";
                webUrl = HttpMethod.USER_ABOUT;
                break;
            case 3:
                title = "圈子创建协议";
                webUrl = HttpMethod.CIRCLE_AGREEMENT;
                break;
            case 4:
                title = "";
                String url = bundle.getString(WEB_URL);
                webUrl = url;
                break;
            case 5:
                title =  "抽奖规则";
                webUrl = HttpMethod.SHARE_LUCK_RULE;
                break;
        }
        setTitle(title, true, TITLE_TYPE_IMG, R.drawable.icon_back, false, -1, -1);

        webView = (WebView) findViewById(R.id.webView);
        WebSettings settings = webView.getSettings();
        //支持javascript
        settings.setJavaScriptEnabled(true);
        //自适应屏幕
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        settings.setLoadWithOverviewMode(true);

        loadWaitDialog();
        webView.loadUrl(webUrl);
        initListener();
    }
    private void initListener(){
        webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress == 100) {
                    // 网页加载完成
                    dismissWaitDialog();
                } else {
                    // 加载中
                }
            }
        });
    }
}
